package com.lotter.common.util;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.collections.CollectionUtils;

import com.lotter.common.enumobject.UserAccountLevelEunm;

public class BigdecimalUtil {
	
	
	/**
	 * 计算最高奖金
	 * @param multiple
	 * @param bigargs
	 * @return
	 */
	public static long amoutWinning(Integer multiple,BigDecimal... bigargs) throws RuntimeException{
		if(multiple == null || bigargs== null || bigargs.length < 1){
			throw new RuntimeException();
		}
		
		//一注2元  等值于200 分
		BigDecimal amount = new BigDecimal(200 * multiple);
		
		for (BigDecimal actualOdds : bigargs) {
			if (amount != null) {
				amount = amount.multiply(actualOdds);
			}
		}
		amount = amount.setScale(0,BigDecimal.ROUND_HALF_UP);
		return  amount.longValue();
	}
	
	
	
	/**
	 * 计算最高奖金
	 * @param multiple
	 * @param bigargs
	 * @return
	 */
	public static long amoutWinning(Integer multiple,List<BigDecimal> bigdecList) throws RuntimeException{
		if(multiple == null || CollectionUtils.isEmpty(bigdecList)){
			throw new RuntimeException();
		}
		
		//一注2元  等值于200 分
		BigDecimal amount = new BigDecimal(200 * multiple);
		
		for (BigDecimal actualOdds : bigdecList) {
			if (amount != null) {
				amount = amount.multiply(actualOdds);
			}
		}
		amount = amount.setScale(0,BigDecimal.ROUND_HALF_UP);
		return  amount.longValue();
	}
	
	/**
	 * 分润
	 * @param amount
	 * @param bigargs
	 * @return
	 */
	public static long sharebenefit(long amount,int hourselevel) throws RuntimeException{
		if(amount  < 0L){
			throw new RuntimeException();
		}
		double share_commission =UserAccountLevelEunm.getNum(hourselevel);
		if(share_commission == 0L ){
			return amount;
		}
		
		BigDecimal sharebenefit = null ;
		sharebenefit = new BigDecimal(amount).multiply(new BigDecimal(share_commission))
				.setScale(0,BigDecimal.ROUND_HALF_UP);
		return  sharebenefit.longValue();
	}
	
	/**
	 * 红单率
	 * @param already_winning
	 * @param not_winning
	 * @return
	 * @throws RuntimeException
	 */
	public static int CalRedRate(int already_winning,int not_winning) throws RuntimeException{
		if(already_winning < 1){
			return 0 ;
		}
		BigDecimal redrate = new BigDecimal(already_winning)
		.divide(new BigDecimal(already_winning).add(new BigDecimal(not_winning)),10,BigDecimal.ROUND_HALF_UP)
		.multiply(new BigDecimal(100))
		.setScale(0, BigDecimal.ROUND_HALF_UP);
		return 	redrate.intValue();	
	}
	
	
	
	public static void main(String[] args) {
	/*	System.out.println(BigdecimalUtil.amoutWinning(10, new BigDecimal(1.9),
				 new BigDecimal(1.91), new BigDecimal(1.09), new BigDecimal(1.39), new BigDecimal(1.49)));
		*/
		List<BigDecimal> bigdecList  = new ArrayList<BigDecimal>();
		bigdecList.add( new BigDecimal(1.9));
		bigdecList.add( new BigDecimal(1.91));
		bigdecList.add( new BigDecimal(1.09));
		bigdecList.add( new BigDecimal(1.39));
		bigdecList.add( new BigDecimal(1.49));
		//System.out.println(BigdecimalUtil.amoutWinning(10, bigdecList));
		
		//System.out.println(BigdecimalUtil.sharebenefit(524253L));
		
		System.out.println(BigdecimalUtil.CalRedRate(0, 0));
	}

}
